package com.soilflow.info.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.soilflow.common.core.domain.entity.SysUser;
import com.soilflow.common.domain.DahuBusiness;
import com.soilflow.common.domain.DahuRecruit;
import com.soilflow.common.utils.DateUtils;
import com.soilflow.common.utils.SecurityUtils;
import com.soilflow.info.mapper.DahuRecruitMapper;
import com.soilflow.info.service.IDahuRecruitService;
import com.soilflow.system.mapper.DahuBusinessMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author party
 * @date 2023-11-02
 */
@Service
public class DahuRecruitServiceImpl extends ServiceImpl<DahuRecruitMapper,DahuRecruit> implements IDahuRecruitService {
    @Resource
    private DahuRecruitMapper dahuRecruitMapper;
    @Resource
    private DahuBusinessMapper dahuBusinessMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public DahuRecruit selectDahuRecruitById(Long id)
    {
        return dahuRecruitMapper.selectDahuRecruitById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param dahuRecruit 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<DahuRecruit> selectDahuRecruitList(DahuRecruit dahuRecruit) {
        List<DahuRecruit> dahuRecruits = dahuRecruitMapper.selectDahuRecruitList(dahuRecruit);
        for (DahuRecruit recruit : dahuRecruits) {
            Long createId = recruit.getCreateId();
            DahuBusiness business = dahuBusinessMapper.selectById(createId);
            recruit.setDahuBusiness(business);
        }
        return dahuRecruits;
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param dahuRecruit 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertDahuRecruit(DahuRecruit dahuRecruit) {
        dahuRecruit.setCreateTime(DateUtils.getNowDate());
        return dahuRecruitMapper.insert(dahuRecruit);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param dahuRecruit 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateDahuRecruit(DahuRecruit dahuRecruit)
    {
        dahuRecruit.setUpdateTime(DateUtils.getNowDate());
        SysUser user = SecurityUtils.getLoginUser().getUser();
        dahuRecruit.setUpdateBy(user.getNickName());
        dahuRecruit.setUpdateId(user.getUserId());
        return dahuRecruitMapper.updateById(dahuRecruit);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteDahuRecruitByIds(Long[] ids)
    {
        for (Long id : ids) {
            LambdaUpdateWrapper<DahuRecruit> wrapper=new LambdaUpdateWrapper<>();
            wrapper.eq(DahuRecruit::getId,id);
            wrapper.set(DahuRecruit::getDeleted,1);
            int update = dahuRecruitMapper.update(null, wrapper);
        }
        return 1;
//        return dahuRecruitMapper.deleteDahuRecruitByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteDahuRecruitById(Long id)
    {
        return dahuRecruitMapper.deleteDahuRecruitById(id);
    }
}
